package com.resource.utils;

import cn.hutool.db.Page;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 前端信息交互分页
 *
 * @Author Tao.yu
 * @CreateDate 2019/11/22
 */
@Data
public class PageInfo<T> implements Serializable {

	private static final long serialVersionUID = 1L;
	/**
	 * 总记录数
	 */
	protected long total;
	/**
	 * 结果集
	 */
	protected List<T> list;

	public PageInfo(List<T> list) {
		this.list = list;
		if (list instanceof Page) {
			this.total = ((Page) list).getPageNumber();
		} else {
			this.total = list.size();
		}
	}

	public PageInfo() {
		if (CollectionUtils.isEmpty(this.list)) {
			this.list = new ArrayList<>();
		}
	}
}
